package com.chhh.cranelease;

import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.http.MediaType;

import java.util.ArrayList;
import java.util.List;

@SpringBootApplication
public class CraneLeaseApplication {

    public static void main(String[] args) {
        SpringApplication.run(CraneLeaseApplication.class, args);
    }
    // 集成FastJson相关功能
    @Bean
    public HttpMessageConverters fastJsonHttpMessageConverters() {
        FastJsonHttpMessageConverter4 fastJsonHttpMessageConvert = new FastJsonHttpMessageConverter4();
        List<MediaType> mediaTypes = new ArrayList<MediaType>();
        mediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
        fastJsonHttpMessageConvert.setSupportedMediaTypes(mediaTypes);
        FastJsonConfig config = new FastJsonConfig();
        config.setDateFormat("YYYY-MM-dd HH:mm:ss");
        config.setSerializerFeatures(SerializerFeature.PrettyFormat);

        fastJsonHttpMessageConvert.setFastJsonConfig(config);

        return new HttpMessageConverters(fastJsonHttpMessageConvert);
    }
}
